<?php
class Controller_Test_Upload extends Controller
{
    public function __construct ($request, $response)
    {
        parent::__construct($request, $response);
    }

    public function action_upload()
    {
        $verifyToken = md5('unique_salt' . $_POST['timestamp']);
        if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
            list($url, $pos) = Media::upload(Kohana::config('env.thumbnail.icon_list'));
            echo $url;
            /*
	        $tempFile = $_FILES['Filedata']['tmp_name'];
	        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
	        $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name'];
	
	        // Validate the file type
	        $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
	        $fileParts = pathinfo($_FILES['Filedata']['name']);
	
	        if (in_array($fileParts['extension'],$fileTypes)) {
		        move_uploaded_file($tempFile,$targetFile);
		        echo '1';
	        } else {
		        echo 'Invalid file type.';
	        }
            */
        }
    }
}
